﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;

namespace Derrick.Web
{
    public sealed class CometRequestPool
    {
        private static volatile HttpWebRequest _cometRequest;
        private static object _lockObj = new object();
        private static volatile CometRequestPool _poolObj;

        private CometRequestPool()
        {
            //_lockObj = new object();
            
        }

        public static CometRequestPool Instance
        {
            get
            {
                if (null == _poolObj)
                {
                    lock (_lockObj)
                    {
                        if (null == _poolObj)
                        {
                            _poolObj = new CometRequestPool();
                        }
                    }
                }
                return _poolObj;
            }
        }

        public HttpWebRequest CometRequest
        {
            get { return _cometRequest; }
            set { _cometRequest = value; }
        }

        public CometRequestPool GetCometRequestPool(string cometUrl)
        {
            _poolObj.CometRequest = (HttpWebRequest)HttpWebRequest.Create(cometUrl);
            return _poolObj;
        }


    }
}